class Solution4 {
    public String countAndSay(int n) {
        StringBuilder s1= new StringBuilder("1");
        StringBuilder s2=new StringBuilder();
        int i=0;
        int j=0;
        while(n-1!=0){
            int len=s1.length();
            i=0;
            j=0;
            while(j<len){
                char ch1=s1.charAt(i);
                char ch2=s1.charAt(j);
                if(ch1!=ch2){
                    s2.append(j-i);
                    s2.append(ch1);
                    i=j;

                }
                j++;

            }
            char ch1=s1.charAt(i);
            s2.append(j-i);
            s2.append(ch1);
            s1=s2;
            s2=new StringBuilder();
            n--;
        }
        return s1.toString();
    }
}